﻿(function (lib, config) {
    var loadFunc = function () {
        var wordAry = config.words.split('|'), bgcolorAry = config.bgcolor.split('|').textcolorAry = config.textcolor.split('|');
        var widgetName = 'weixin' + Date.now();
        config.width = 65, config.height = 65;
        /*TODO 方法*/
        var htmlStr = [
            '<style type="text/css">',
            '#{{widgetName}}{display: none; ;width:65px; '+lib.util.getPosStyle(config)+'position: fixed; z-index: 9999999; }',
            '.dh{animation:dh 2s linear 1 forwards;-webkit-animation:dh 2s linear 1 forwards;}',
            '@keyframes dh{',
            '	0%{ top:-27%;}	',
            '	50%{ top:22%;}	',
            '	60%{ top:27%;}	',
            '	70%{ top:22%;}	',
            '	80%{ top:27%;}	',
            '	90%{ top:22%;}	',
            '	100%{ top:27%;} ',
            '}',
            '@-webkit-keyframes dh{',
            '	0%{ top:-27%;}	',
            '	50%{ top:22%;}	',
            '	60%{ top:27%;}	',
            '	70%{ top:22%;}	',
            '	80%{ top:27%;}	',
            '	90%{ top:22%;}	',
            '	100%{ top:27%;} ',
            '}',
            '</style>',
            '<a class="dh" href="/swt/" id="{{widgetName}}"><img src="http://3g.beijinfhfuk.com/swt/images/wxico.png" alt=""></a>',
        ].join('');
        htmlStr = lib.util.resolveTemplate(htmlStr, 'widgetName', widgetName);
        setTimeout(function () {
            var o = document.createElement('div');
            o.innerHTML = htmlStr;
            while (o.firstElementChild) {
                document.body.appendChild(o.firstElementChild);
            }
            weixinShow();
        }, config.firsttime * 1000);
        function weixinShow() {
            document.getElementById(widgetName).style.display = 'block';
            if (+config.eachtime > 0) setTimeout(weixinHide, config.eachtime * 1000);
        }
        function weixinHide() {
            document.getElementById(widgetName).style.display = 'none';
            if (+config.relapsetime > 0) setTimeout(weixinShow, config.relapsetime * 1000);
        }

    };

    lib.load(loadFunc);
    /*执行代码*/
})('{{lib}}', '{{config}}');